package com.dai.code;

import java.util.Stack;

/**
 * 最大栈
 * @author daijiyong
 */
public class MaxHeap {
    private final Stack<Integer> stack;
    private final Stack<Integer> stackMax;

    public MaxHeap() {
        this.stack = new Stack<>();
        this.stackMax = new Stack<>();
    }

    public Integer peekMax() {
        return stackMax.peek();
    }

    public Integer push(Integer item) {
        if (stack.isEmpty()) {
            stackMax.push(item);
        } else {
            if (item > stackMax.peek()) {
                stackMax.push(item);
            } else {
                stackMax.push(stackMax.peek());
            }
        }
        stack.push(item);
        return item;
    }

    public Integer peek() {
        return stack.peek();
    }

    public Integer pop() {
        stackMax.pop();
        return stack.pop();
    }
}